
#ifndef _BLOCK_POOL_H_
#define _BLOCK_POOL_H_

#ifndef BLOCK_POOL_SIZ_SIZE
#define BLOCK_POOL_SIZ_SIZE 2
#endif

#if (BLOCK_POOL_SIZ_SIZE == 1)
typedef uint8_t BPoolSize;
#elif (BLOCK_POOL_SIZ_SIZE == 2)

typedef uint16_t BPoolSize;
#elif (BLOCK_POOL_SIZ_SIZE == 4)
typedef uint32_t BPoolSize;
#else
#error "BLOCK_POOL_SIZ_SIZE defined incorrectly, expected 1, 2, or 4"
#endif

/****************************************************************************/
#ifndef BLOCK_POOL_CTR_SIZE
#define BLOCK_POOL_CTR_SIZE 2
#endif
#if (BLOCK_POOL_CTR_SIZE == 1)
typedef uint8_t BPoolCtr;
#elif (BLOCK_POOL_CTR_SIZE == 2)
typedef uint16_t BPoolCtr;
#elif (BLOCK_POOL_CTR_SIZE == 4)
typedef uint32_t BPoolCtr;
#else
#error "BLOCK_POOL_CTR_SIZE defined incorrectly, expected 1, 2, or 4"
#endif

typedef struct BPoolFreeTag
{
    struct BPoolFreeTag *next;
} BPoolFree;


typedef struct 
{
    /** The head of the linked list of free blocks
    */
    void *free;

    /** the original start this pool
    */
    void *start;

    /** the last memory block managed by this memory pool
    */
    void *end;

    /**  maximum block size (in bytes)
    */
    BPoolSize blockSize;

    /** total number of blocks
    */
    BPoolCtr nTot;

    /** number of free blocks remaining
    */
    BPoolCtr nFree;

    /** minimum number of free blocks ever present in this pool
    *
    * \note this attribute remembers the low watermark of the pool,
    * which provides a valuable information for sizing event pools.
    * \sa QF_getPoolMargin().
    */
    BPoolCtr nMin;
} BPool;


void BPool_Init(BPool *bpool, void *poolSto,
                 uint32_t poolSize, BPoolSize blockSize);

void *BPool_Get(BPool *bpool);

void BPool_Put(BPool *bpool, void *b);


#endif

